#ifndef __BSP_GPIO_H_
#define __BSP_GPIO_H_

#include "stm32f10x.h"

/* NFC 复位 */
#define NFC_RESET_PIN       GPIO_Pin_11
#define NFC_RESET_PORT      GPIOA

/* 4G Power */
#define E4G_POWER_PIN       GPIO_Pin_13
#define E4G_POWER_PORT      GPIOC

/* 4G RESET */
#define E4G_RESET_PIN       GPIO_Pin_9
#define E4G_RESET_PORT      GPIOB

/* 蓝牙唤醒 */
#define BLE_WAKEUP_PIN      GPIO_Pin_4
#define BLE_WAKEUP_PORT     GPIOB

/* 蓝牙复位 */
#define BLE_RESET_PIN       GPIO_Pin_7
#define BLE_RESET_PORT      GPIOB

/* 短路检测 */
#define SHORT_CIRCUIT_PIN   GPIO_Pin_4
#define SHORT_CIRCUIT_PORT  GPIOC

/* 主回路继电器 */
#define AC_RELAY_PIN        GPIO_Pin_5
#define AC_RELAY_PORT       GPIOC

/* 漏电流测试 */
#define RCD_TEST_PIN        GPIO_Pin_3
#define RCD_TEST_PORT       GPIOB

/* 漏电流校准 */
#define RCD_CAL_PIN         GPIO_Pin_8
#define RCD_CAL_PORT        GPIOB


/* PA0 - 漏电流故障反馈   */
#define RCD_TRIP_PIN        GPIO_Pin_0
#define RCD_TRIP_PORT       GPIOA

/* PA1 - 蓝牙连接状态反馈 */
#define BLE_CONNT_PIN       GPIO_Pin_1
#define BLE_CONNT_PORT      GPIOA

/* PA8 - 继电器黏连       */
#define K1_FAULT_PIN         GPIO_Pin_8
#define K1_FAULT_PORT        GPIOA

/* PC7 - 继电器黏连       */
#define K2_FAULT_PIN         GPIO_Pin_7
#define K2_FAULT_PORT        GPIOC

/* PC8 - 火线接地          */
#define NE_PIN              GPIO_Pin_8
#define NE_PORT             GPIOC

/* PC9 - 零线接地          */
#define LE_PIN              GPIO_Pin_9
#define LE_PORT             GPIOC

#define BUZZER_PIN          GPIO_Pin_6
#define BUZZER_PORT         GPIOB

#define EC4G_PWRKEY_PORT    GPIOC
#define EC4G_PWRKEY_PIN     GPIO_Pin_13

#define EC4G_RESET_PORT     GPIOB
#define EC4G_RESET_PIN      GPIO_Pin_9

void gpio_port_init(void);
void ec800_gpio_config(void);
void e4g_power_set(uint8_t val);
void e4g_reset_set(uint8_t val);
void rcd_test_set(uint8_t val);
void rcd_cal_set(uint8_t val);
void short_circuit_set(uint8_t val);
void ac_relay_set(uint8_t val);
void ble_wakeup_set(uint8_t val);
void ble_reset_set(uint8_t val);
void nfc_reset_pin_set(uint8_t val);

uint8_t rcd_trip_read(void);
uint8_t ble_connt_read(void);
uint8_t k1_fault_read(void);
uint8_t k2_fault_read(void);
uint8_t ne_read(void);
uint8_t le_read(void);
uint8_t buzzer_set(uint8_t val);

#define EC4G_PWRKEY(val)        do{ \
                                    val ? GPIO_SetBits(EC4G_PWRKEY_PORT,  EC4G_PWRKEY_PIN): \
                                          GPIO_ResetBits(EC4G_PWRKEY_PORT,EC4G_PWRKEY_PIN); \
                                  }while(0)

#define EC4G_RESET(val)        do{ \
                                    val ? GPIO_SetBits(EC4G_RESET_PORT,   EC4G_RESET_PIN): \
                                          GPIO_ResetBits(EC4G_RESET_PORT, EC4G_RESET_PIN); \
                                  }while(0)

#endif

